// pages/register/index.js
import net from '../../utils/net.js'
import { inputgetName } from '../../utils/inputBothBind.js'


Page({
  data: {
    iconPath:'/assets/images/home_a.png',
    username: '',
    password:'',
    invateCode: '',
    smsCode:'',
    agreeProtocol: false
  },
  inputgetName: inputgetName,
  toSeeProtocol:function() {
    wx.navigateTo({
      url: "/pages/web/index",
      event:{
        
      },
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', { url: 'https://m.xliank.com/api/share/registration_protocol?platform=xinlianka' })
      }
    })
  },
  switchProtocol:function() {
    this.setData({
      agreeProtocol: !this.data.agreeProtocol
    })
  },

  register:function() {
    console.log(this.data.username)
    console.log(this.data.password)
    console.log(this.data.smsCode)
    console.log(this.data.invateCode)
    return
    if (!this.data.username || !this.data.password || !this.data.smsCode || !this.data.invateCode) {
      wx.showToast({
        title: '请填写完整',
        icon: 'none'
      })
      return
    }
    if (!agreeProtocol) {
      wx.showToast({
        title: '您还未同意注册协议',
        icon: 'none'
      })
      return
    }
    net.http({
      url: '/api/index/index?method=register',
      data: {
        tel: this.data.username,
        password: this.data.password,
        share_tel: this.data.invateCode,
        sms_code: this.data.smsCode
      },
      isShowLoading: true,
      successCb: registerSucCb
    })
  },

  registerSucCb:function(res) {
    wx.showToast({
      title: res.msg,
      icon: 'success'
    })
    setTimeout(function() {
      wx.navigateBack({
        delta: 1,
      })
    }, 500)
  },
  smsCodeChange(data) {
    console.log(data.detail.value)
    console.log(data)
    console.log(a)
  },
  validTel() {
    console.log(this.data.username)
  }
})